Skip to content

feat(token-2022/nft-meta-data-pointer): add pinocchio example - #718

Open
MarkFeder wants to merge 2 commits into
solana-foundation:mainfrom
MarkFeder:tokens-token-2022-nft-meta-data-pointer-pinocchio
Open

feat(token-2022/nft-meta-data-pointer): add pinocchio example#718
MarkFeder wants to merge 2 commits into
solana-foundation:mainfrom
MarkFeder:tokens-token-2022-nft-meta-data-pointer-pinocchio

Conversation

@MarkFeder

Copy link
Copy Markdown
Contributor

Ports tokens/token-2022/nft-meta-data-pointer to Pinocchio.

An NFT whose metadata lives in the mint itself via the Token-2022 MetadataPointer extension (pointing at the mint), so there is no separate metadata account. A small chop-the-tree game writes the player's banked wood onto that metadata as they play, which is what makes the pointer worth demonstrating: the token's own data tracks progress, no indexer involved.

  • init_player — creates the player PDA and the shared level PDA (only the first player pays for the level)
  • mint_nft — 234-byte mint, MetadataPointer → mint, InitializeMint2 (0 decimals), metadata initialize + level=1, ATA, mint 1, then SetAuthority(MintTokens, None) so the supply is fixed at one. The metadata authority stays with the program PDA, which is what lets chop_tree keep updating it.
  • chop_tree — spends energy, banks wood, rewrites wood on the mint's metadata

There is no pinocchio crate for Token-2022 or the token-metadata interface, so those CPIs are built by hand; the discriminators are documented from their preimages rather than pasted.

One deliberate omission: the Anchor example routes chop_tree through gum session keys, which have no Pinocchio equivalent and are orthogonal to what this example teaches. Here chop_tree requires the player's own signature (player.authority == signer). Everything else matches the reference, including on_tree_chopped's pre-add level comparison.

Tests use LiteSVM + @solana/kit; 8 tests cover both instructions plus the energy refill and the authority check. Rent is topped up after metadata writes, since UpdateField grows the mint.

@MarkFeder
MarkFeder requested a review from dev-jodee as a code owner August 31, 2026 20:37
@greptile-apps

greptile-apps Bot commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

The PR adds a Pinocchio implementation of the Token-2022 metadata-pointer NFT game.

  • Adds player and shared-level initialization, NFT minting, and tree-chopping instructions.
  • Builds Token-2022 metadata CPIs manually and updates the mint’s on-chain wood field.
  • Adds LiteSVM tests, package configuration, workspace registration, and documentation.

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Important Files Changed

Filename Overview
tokens/token-2022/nft-meta-data-pointer/pinocchio/program/src/instructions/chop_tree.rs Validates player authority, NFT possession, and the Token-2022 program before updating game state and mint metadata; the previously reported account-boundary issues are fixed.
tokens/token-2022/nft-meta-data-pointer/pinocchio/program/src/instructions/mint_nft.rs Creates the extended mint, initializes self-referential metadata, mints one token, and revokes mint authority.
tokens/token-2022/nft-meta-data-pointer/pinocchio/program/src/instructions/init_player.rs Initializes the player PDA and lazily creates the shared game-level PDA.
tokens/token-2022/nft-meta-data-pointer/pinocchio/program/src/metadata.rs Encodes and invokes Token-2022 metadata initialization and field-update instructions.
tokens/token-2022/nft-meta-data-pointer/pinocchio/program/src/state.rs Defines and mutates the player and level account layouts used by the game instructions.
tokens/token-2022/nft-meta-data-pointer/pinocchio/tests/test.ts Exercises initialization, minting, chopping, refill behavior, authority validation, NFT ownership validation, and token-program validation.

Reviews (2): Last reviewed commit: "nft-meta-data-pointer: bind the mint to ..." | Re-trigger Greptile

…program

chop_tree accepted any Token-2022 mint, and every NFT this program mints
shares one metadata authority, so a valid player could rewrite another
player's wood. It also invoked the metadata CPI against the caller-supplied
program slot. The reference pins that slot with Program<'info, Token2022>
and builds the instruction against spl_token_2022::id(); its mint account
documents the holder check in a CHECK comment but never enforces it.
@MarkFeder

Copy link
Copy Markdown
Contributor Author

@amilz could you take a look at this one when you get a chance?

No open review threads left on it, so it is ready for maintainer review. It is one of 23 open Pinocchio ports I have up — they are independent and self-contained, so they can be reviewed and merged in any order: https://github.com/solana-developers/program-examples/pulls/MarkFeder

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant